package com.imooc.pan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.imooc.pan.core.response.R;
import com.imooc.pan.entity.StorageBusiness;
import com.imooc.pan.entity.StorageOrder;
import com.imooc.pan.service.StorageBusinessService;
import com.imooc.pan.service.StorageOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Janson
 * @Description TODO
 * @Date 2023/8/1
 */
@RestController
@RequestMapping("")
public class StorageBusinessController {
    
    @Autowired
    private StorageBusinessService storageBusinessService;
    
    @Autowired
    private StorageOrderService storageOrderService;
    /**
     * 查询全部套餐数据
     * @return
     */
    @GetMapping("sotageBusinessList")
    public R list(){
        List<StorageBusiness> storageBusinessList = storageBusinessService.list(null);
        return R.data(storageBusinessList);
    }
    
    /**
     * 保存用户订单
     * @return
     */
    @GetMapping("saveOrders")
    public R saveOrders(@RequestParam("id") Long id){
        String payNo = storageOrderService.saveUserOrder(id);
        return R.data(payNo);
    }
    
    @GetMapping("getOrdersByPayNo")
    public R getOrder(@RequestParam("payNo") String payNo){
        LambdaQueryWrapper<StorageOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StorageOrder::getPayNo,payNo);
        StorageOrder storageOrder = storageOrderService.getOne(queryWrapper);
        return R.data(storageOrder);
    }
}
